﻿using System;
using System.Collections.Generic;
using System.Text;
using Dora.Services.AdminUser.Entities;
using Dora.Orm.SqlSugarCore.UnitOfWork;
using System.Threading.Tasks;


namespace Dora.Services.AdminUser.Repository.Repositorys
{
   public class ParamsMapRepository:SqlSugarRepository<ParamsMapEntity,int>
    {
        private ISugarUnitOfWork _unitOfWork;
        public ParamsMapRepository(ISugarUnitOfWork unitOfWork) : base(unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }


        /// <summary>
        /// 根据参数值，参数类型获取参数映射表信息
        /// </summary>
        /// <param name="Params"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public async Task<ParamsMapEntity> GetInfoByParams(ParamsMapEntity entity)
        {
            var result = await _unitOfWork.QueryClient.Queryable<ParamsMapEntity>()
                .Where(it => it.ParamsValue == entity.ParamsValue && it.ParamsType == entity.ParamsType).FirstAsync();

            return result;
        }

        /// <summary>
        /// 修改表更新人，更新时间
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<bool> UpdateInfo(ParamsMapEntity entity)
        {
            var result = await  _unitOfWork.ModifyClient.Updateable<ParamsMapEntity>()
                .SetColumns(it => new ParamsMapEntity() { UpdatedUserId = entity.UpdatedUserId, UpdatedUserName = entity.UpdatedUserName, UpdatedTime = DateTime.Now })
                .Where(it => it.Id == entity.Id).ExecuteCommandAsync() > 0;
            return result;
        }
    }
}
